<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="球员姓名">
        <el-input v-model="play.name"/>
      </el-form-item>
      <el-form-item label="进球数">
        <el-input v-model="playData.score"/>
      </el-form-item>
      <el-form-item label="传球数">
        <el-input v-model="playData.pass"/>
      </el-form-item>
      <el-form-item label="射门数">
        <el-input v-model="playData.shoot"/>
      </el-form-item>
      <el-form-item label="助攻数">
        <el-input v-model="playData.assist"/>
      </el-form-item>
      <el-form-item label="上场时间(分钟)">
        <el-input v-model="playData.playingTime"/>
      </el-form-item>

      <!-- 讲师头像：TODO -->

      <el-form-item>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveData">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import data from '@/api/dbwork/playData'
  import player from '@/api/dbwork/player'
  export default {
      data(){
        return{
            playData:{},
            play:{}
        }
      },
      created() {
        // 由于本界面是修改和添加公用的，通过判断id是否有值来确定到底是修改还是添加
        if(this.$route.params&&this.$route.params.id){
          const id = this.$route.params.id
          this.playData.playerId = id
          this.getPlayer(id)
        }
      },
      methods:{
        getPlayer(id){
          player.getPlayerById(id)
            .then(response=>{
              this.play = response.data.player
            })
        },
        saveData(){
          // alert(this.playData.playerId)
          data.setData(this.playData)
          .then(response=>{
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
            this.$router.push({path:'/player/table'})
          })
        }
      }
  }
</script>
